import 'package:dmz/base/pageWidget/base_stateful_widget.dart';

import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/mine/controller/garage_main_controller.dart';
import 'package:dmz/business/mine/model/share_model.dart';
import 'package:dmz/business/mine/widget/garage_widgets.dart';
import 'package:dmz/utils/sp_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class AcceptWdiegt extends StatelessWidget {
  const AcceptWdiegt({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<GarageController>(
        id: 'accept',
        builder: (controller) {
          return controller.acceptModels.isEmpty
              ? GarageWidgets.emptyWidget()
              : ListView.builder(
                  itemCount: controller.acceptModels.length,
                  itemBuilder: (context, index) {
                    return lsitItem(controller.acceptModels[index],
                        (data) => controller.addDevice(data));
                  });
        });
  }

  lsitItem(ShareModel data, Function(ShareModel) agree) {
    return Container(
        color: const Color(0xFF434650),
        child: Row(children: [
          motoImage(112.sp, data.photo ?? ''),
          Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            Row(children: [
              DefaultText(data.name, 48.sp,
                  textColor: const Color(0xFFF9F9F9),
                  fontWeight: FontWeight.w700),
              otherNameWidget(data.user_name ?? '')
            ]),
            DefaultText(
                SPUtils.timeIntToTimeStr(data.created_at ?? 0,
                    attern: 'yyyy-MM-dd HH:mm'),
                28.sp,
                textColor: const Color(0xFF999999))
          ]),
          const Expanded(child: SizedBox()),
          if (data.status == 1)
            DefaultText('接受'.tr, 32.sp, textColor: const Color(0xFF23C565))
                .marginOnly(right: 62.sp)
                .addGestureDetector(() => agree(data))
        ])).marginOnly(bottom: 20.sp);
  }

  otherNameWidget(String content) {
    return Container(
            padding: EdgeInsets.only(left: 12.sp, right: 12.sp),
            constraints: BoxConstraints(maxWidth: 320.sp),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(56.sp), // 设置圆角半径
                border: Border.all(
                  color: const Color(0xFF23C565), // 设置边框颜色
                  width: 2.sp, // 设置边框宽度
                )),
            child: DefaultText('${'分享人：'.tr}$content', 28.sp,
                textColor: const Color(0xFF23C565),
                overflow: TextOverflow.ellipsis))
        .marginOnly(left: 20.sp);
  }

  motoImage(double width, String url) {
    return Container(
            color: const Color(0xFFA1A2A7),
            child: DefaultNetWorkImage(url, width: width, height: width))
        .didClipRRectAll(width)
        .marginOnly(top: 40.sp, bottom: 40.sp, right: 32.sp, left: 30.sp);
  }
}
